package com.wz.project.stock.stockdetail.controller;

import java.util.List;

import com.wz.project.stock.domain.BasStock;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.stock.stockdetail.domain.BasStockDetail;
import com.wz.project.stock.stockdetail.service.IBasStockDetailService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 子库存查询Controller
 * 
 * @author wld
 * @date 2023-10-17
 */
@Controller
@RequestMapping("/stock/stockdetail")
public class BasStockDetailController extends BaseController
{
    private String prefix = "stock/stockdetail";

    @Autowired
    private IBasStockDetailService basStockDetailService;

//    @RequiresPermissions("stock:stockdetail:view")
    @GetMapping()
    public String stockdetail()
    {
        return prefix + "/stockdetail";
    }

    /**
     * 查询子库存查询列表
     */
//    @RequiresPermissions("stock:stockdetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasStockDetail basStockDetail)
    {
        startPage();
        List<BasStockDetail> list = basStockDetailService.selectBasStockDetailList(basStockDetail);
        return getDataTable(list);
    }


    /**
     * 导出子库存查询列表
     */
//    @RequiresPermissions("stock:stockdetail:export")
    @Log(title = "子库存查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasStockDetail basStockDetail)
    {
        List<BasStockDetail> list = basStockDetailService.selectBasStockDetailList(basStockDetail);
        ExcelUtil<BasStockDetail> util = new ExcelUtil<BasStockDetail>(BasStockDetail.class);
        return util.exportExcel(list, "stockdetail");
    }

    /**
     * 新增子库存查询
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存子库存查询
     */
    @RequiresPermissions("stock:stockdetail:add")
    @Log(title = "子库存查询", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasStockDetail basStockDetail)
    {
        return toAjax(basStockDetailService.insertBasStockDetail(basStockDetail));
    }

    /**
     * 修改子库存查询
     */
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("fbarcode") String fbarcode, ModelMap mmap)
    {
        BasStockDetail basStockDetail = basStockDetailService.selectBasStockDetailById(fbarcode);
        mmap.put("basStockDetail", basStockDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存子库存查询
     */
    @RequiresPermissions("stock:stockdetail:edit")
    @Log(title = "子库存查询", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasStockDetail basStockDetail)
    {
        return toAjax(basStockDetailService.updateBasStockDetail(basStockDetail));
    }

    /**
     * 删除子库存查询
     */
    @RequiresPermissions("stock:stockdetail:remove")
    @Log(title = "子库存查询", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basStockDetailService.deleteBasStockDetailByIds(ids));
    }
}
